<div class="sign-title"><h2>找回密码</h2></div>
<!-- 步骤图 -->
<div id="forgot_steps" class="steps forgot-steps">
  <table width="100%">
    <tbody>
      <tr>
        <td class="step-item step-1 active"><span><q class="icon">&#x50;</q><i>1</i>填写账户名</span></td>
        <td class="icon step-arrow">&#x28;</td>
        <td class="step-item step-2"><span><q class="icon">&#x50;</q><i>2</i>身份验证</span></td>
        <td class="icon step-arrow">&#x28;</td>
        <td class="step-item step-3"><span><q class="icon">&#x50;</q><i>3</i>设置新密码</span></td>
        <td class="icon step-arrow">&#x28;</td>
        <td class="step-item step-4"><span><q class="icon">&#x50;</q><i>4</i>完成</span></td>
      </tr>
    </tbody>
  </table>
</div>

<!-- 找回密码 -->
<div id="forgot_content" class="forgot-content signupin-content">
  <form action="<{link app=b2c ctl=site_passport act=sendPSW}>" method="post">
    <input name="forward" type="hidden" value="<{$options.url}>">
    <ul>
      <li class="form-item">
        <label for="" class="form-label">账户名：</label>
        <span class="form-act"><{input type="text" name="username" id="" placeholder="用户名/手机号码/邮箱地址" autofocus vtype="required" data-caution="请填写您的账户名"}></span>
        <span class="caution-content"><{$msg}></span>
      </li>
      <li class="form-item-normal">
        <span class="form-act"><{button type="submit" label=$___b2c="下一步"|t:'b2c' class="btn-caution btn-big" rel="_request" data-ajax-config="{onSuccess:function(rs){changeStep(rs, 2);}}"}> <span class="forgot-remember">记起密码？ <a href="<{link app=b2c ctl=site_passport act=login}>" class="goto-signin">登录</a></span></span>
      </li>
    </ul>
  </form>
</div>
<script>
var module = $('forgot_content');
var Query = {
    send: function(url, data, fn){
        new Request({
            url: url,
            link: 'cancel',
            onSuccess: function(rs) {
                if(rs) {
                    try{
                        rs = JSON.decode(rs);
                    } catch (e) {}
                    if(typeof rs.error === 'string') Message.error(rs.error);
                    fn&&fn.call(this, rs);
                }
            }
        }).post(data);
    }
};

function changeStep(rs, x, fn) {
    if(rs && rs[0]) {
        if(typeOf(rs[0]) === 'string') {
            module.innerHTML = rs[0];
            if(x) $('forgot_steps').getElement('.active').removeClass('active').getSiblings('.step-' + x).addClass('active');
        }
        else if(typeOf(rs[0]) === 'object') {
            if(rs[0].error) return Message.error(rs[0].error);
        }
        fn && fn.call(this);
    }
}
module.addEvents({
    'change:relay(.action-verify-method)': function(e) {
        var form = this.getParent('form');
        form.getElements('.op-verify-mobile, .op-verify-email').addClass('hide');
        form.getElements('.op-verify-' + this.value).removeClass('hide');
    },
    'click:relay(.action-resend-email)':function(e) {
        e.stop();
        var url = this.href;
        var data = JSON.decode(this.get('data-params'));
        Query.send(url, data, changeStep);
    },
    'click:relay(.auto-change-verify-handle)': function(e) {
      e.preventDefault();
      changeVerify(this);
    },
    'click:relay(.action-get-verifycode)': function(e) {
        e.stop();
        if(this.hasClass('disabled')) return false;
      <{if $site_sms_valide == 'true'}>
        var form = this.getParent('form');
        if(form.getElement('.sms-verify-input').value == '')
        {
          alert('请输入验证码');
          return;
        }
        sendVerify(this, 'uname=' + this.get('data-mobile') + '&type=forgot' + '&sms_vcode=' + form.getElement('.sms-verify-input').value);
      <{else}>
        sendVerify(this, 'uname=' + this.get('data-mobile') + '&type=forgot');
      <{/if}>
    }
});
function sendVerify(el, data) {
    var url = el.href;
    el.addClass('disabled');
    var textCont = el.getElement('span span');
    textCont.innerHTML = el.get('text') + '(<i>0</i>)';
    var cd = new countdown(textCont.getElement('i'), {
        start: 120,
        secondOnly: true,
        callback: function(e) {
            el.removeClass('disabled');
            textCont.innerHTML = '重发验证码';
        }
    });
    Query.send(url, data, function(rs) {
        if(rs.error) {
            cd.stop();
            el.removeClass('disabled');
            textCont.innerHTML = '重发验证码';
        }
    });
}
</script>
